<?php
/**
 *
 *
 * This file is part of Webappkit, a packages system for PHP web apps
 * @link http://webappkit.net
 * @package
 * @subpackage
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */

/**
 * @property array $attributes
 */
class DjWidget extends DataBean {

    /**
     * renders as HTML
     * @param string $name
     * @param mixed $value value
     * @param array $attributes html attributes like class, size etc
     */
    public function render($name, $value, $attributes=array()) {
        return '';
    }

    /**
     * sets an attribute
     * @param string $name
     * @param string $value
     */
    public function setAttribute($name, $value) {
        $this->attributes[$name] = $value;
        return true;
    }

    protected $attributes=array();
    protected function _attributes_check($x) {
        return is_array($x);
    }

    /**
     * renders html attributes
     * @param array $attributes
     * @param string $name
     * @return string 'name="value" name2="value2"'
     */
    protected function _renderAttributes($attributes=array(), $name='') {
        $attributes = array_merge($this->attributes, $attributes);
        $out = '';
        foreach ($attributes as $name => $value) {
            if ($name=='id')
                continue;
            $out.=$name.'="'.$value.'" ';
        }
        return ($out?' ':'') // un espace avant si non vide
        .trim($out);
    }

    /**
     * renders id attribute
     * @param string $name input name's
     * @return string id="id"
     */
    protected function _renderId($name="") {
        return ' id="id_'.$name.'"';
    }

}